package edu.fiu.cis.personalize.server.clean;

import java.util.ArrayList;
import java.util.List;

public abstract class Filter
{
	private static List<Filter>	filters	= new ArrayList<Filter>();

	static {
		filters.add(new LengthFilter());
		filters.add(new StopWordFilter());
		//filters.add(new DataTypeFilter());
		//filters.add(new DimensionFilter());
		//filters.add(new HyphenatedFilter());
		filters.add(new LongNumberFilter());
		filters.add(new KeyFilter());
	}

	public static void main(String[] args) {
		Filter filter = new KeyFilter();
		String word = "1232abssd121";
		System.out.println(filter.filter(word));
	}

	public static List<Filter> cleaners() {
		return filters;
	}

	public static boolean runFilters(String word) {

		for (Filter c : filters) {
			if (c.filter(word) == false) { return false; }
		}

		return true;
	}

	public abstract boolean filter(String word);

}

class LengthFilter extends Filter
{

	private static final int	KW_LENGTH_THRESHOLD	= 3;

	@Override
	public boolean filter(String word) {
		return word.length() >= KW_LENGTH_THRESHOLD;

		// FIXME add exclusions such as brand names etc
	}

}



class StopWordFilter extends Filter
{

	@Override
	public boolean filter(String word) {
		return StopKeywords.isStopWord(word) == false;
	}

}

class DimensionFilter extends Filter
{

	@Override
	public boolean filter(String word) {
		return !word.matches("[0-9]+[x|X].+");
	}

}

class HyphenatedFilter extends Filter
{

	@Override
	public boolean filter(String word) {
		if (word.indexOf('-') >= 0) {
			String breaks[] = word.split("-");
			return breaks.length == 2;
		}
		return true;
	}

}

class LongNumberFilter extends Filter
{

	@Override
	public boolean filter(String word) {
		return !word.matches("[0-9]{7}.*");
	}

}

class KeyFilter extends Filter
{

	@Override
	public boolean filter(String word) {
		if (word.matches("[0-9]+[a-z]+[0-9]+.*")) { return false; }

		if (word.matches("[a-z]+[0-9]+[a-z]+.*")) { return false; }

		return true;
	}

}


